<template>
  <div class="wrapper">
    <div class="box">
      <div class="top" ref="boxTop">
        <slot name="top"></slot>
      </div>
      <div class="flex mb-24" ref="boxSearch">
        <div class="flex search">
          <slot name="search"></slot>
        </div>
        <div class="flex">
          <slot name="btn"></slot>
        </div>
      </div>
      <div class="table-box" :style="{ height: 'calc(100% - ' + tHeight + 'px)' }">
        <slot name="table"></slot>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
/**
 * 搜索 - 表格页样式组件
 */
import { onMounted, nextTick, getCurrentInstance, ref } from 'vue'
const instance: any = getCurrentInstance()
const tHeight = ref(0)
const handleSetTabelHeight = () => {
  const pHeight = instance?.refs.boxTop && instance?.refs.boxTop.offsetHeight
  const sHeight = instance?.refs.boxSearch && instance?.refs.boxSearch.offsetHeight
  tHeight.value = pHeight + sHeight + (pHeight && 16) + (sHeight && 24)
}
const handleResizeChange = () => {
  ;(window as any).addEventListener('resize', () => {
    handleSetTabelHeight()
  })
}
onMounted(() => {
  nextTick(() => {
    handleSetTabelHeight()
  })
  handleResizeChange()
})
</script>
<style lang="stylus" scoped>
.wrapper
  position relative
  height calc(100vh - 60px)
.mb-24
  margin-bottom 24px
.box
  height: calc(100% - 48px);
  border-radius: 10px;
  overflow: auto;
  background: #fff;
  padding: 24px;

.flex {
  display: flex;
  font-size: 14px;
  justify-content: space-between;
  align-items: flex-end;
}

.search {
  div:not(:first-child) {
    margin-left: 20px;
  }
}

.table-box
  position relative
:deep(.el-form) .el-form-item {
  margin-bottom: 0;
}
</style>
